﻿using System;
using PostSharp.Laos;
using TestBat.IViewModels.Dialogs;
using TestBat.Models.Exceptions;
using TestBat.ServiceLocator;
using TestBat.ViewModels.Dialogs;

namespace TestBat.ViewModels.Attributes
{
    [Serializable]
    class BusinessErrorDialogAttribute : OnMethodBoundaryAspect 
    {
        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
            if (eventArgs.Exception is BusinessException)
            {
                DefaultServiceLocator.Get<IDialogMediator>().DialogViewModel = new BusinessErrorDialogViewModel(eventArgs.Exception);
                eventArgs.FlowBehavior = FlowBehavior.Continue;
            }
        }
    }
}
